//===================================
//File: Throat.cpp
//Throat function
//Name: Smirnova O.P.
//Date: 21.05.12, v.1.0
//===================================




#include "Throat.h"

#include <iostream>

using namespace std;

//---------------------------------------------------------------------------

unsigned int Throat::count=0;
unsigned int Throat::count_all=0;
Throat::Throat()
{
	count_all++;
    id=count_all;
	count++;
    cout <<endl;
//	cout << "\Throat() ";
//	cout <<" id=" <<id<<":\n";
	rect = Rectangle();
	dist = Distance();
//	cout << "a: " << trapeze.getA() << "\n";
//	cout << "d: " << trapeze.getD() << "\n";
//	cout << "h: " << trapeze.getH() << "\n";
///	cout << "P1: " << trapeze.getPoint1() << "\n";
//	cout << "P2: " << trapeze.getPoint2() << "\n";
//	cout << "P3: " << trapeze.getPoint3() << "\n";
//	cout << "P4: " << trapeze.getPoint4() << "\n";
//	cout << "Throat()\n";
//	cout <<" id=" <<id<<endl;

}
// "Говорящий" конструктор с параметрами
Throat::Throat( Point C,  double a, double b)
{
	count_all++;
    id=count_all;
	count++;
    cout <<endl;
//	cout << "\Throat() ";
//	cout <<" id=" <<id<<":\n";
	rect = Rectangle(C,a,b);
	dist = Distance(Point(rect.getPointE().getX()-0.1*a,rect.getPointE().getY(),0),Point(rect.getPointF().getX()+0.1*a,rect.getPointE().getY(),0));

//	cout << "a: " << trapeze.getA() << "\n";
//	cout << "d: " << trapeze.getD() << "\n";
//	cout << "h: " << trapeze.getH() << "\n";
//	cout << "P1: " << trapeze.getPoint1() << "\n";
//	cout << "P2: " << trapeze.getPoint2() << "\n";
//	cout << "P3: " << trapeze.getPoint3() << "\n";
//	cout << "P4: " << trapeze.getPoint4() << "\n";
//	cout << "Throat()\n";
//	cout <<" id=" <<id<<endl;
	
}
//---------------------------------------------------------------------------
Throat::~Throat()
{
	//cout << "\n~Throat:\n";
	
	//cout << "~Throat\n";
	
}
//---------------------------------------------------------------------------
void Throat::moveTo( Point p)
{
	double x0, y0,x1,y1,x2,y2,x3,y3,x4,y4,x5,y5,x6,y6;
	x0=p.getX();
	y0=p.getY();
	x1=rect.getPointC().getX();
	y1=rect.getPointC().getY();
	x2=rect.getPointD().getX();
	y2=rect.getPointD().getY();
	x3=rect.getPointE().getX();
	y3=rect.getPointE().getY();
	x4=rect.getPointF().getX();
	y4=rect.getPointF().getY();
	x5=dist.getPointE1().getX();
	y5=dist.getPointE1().getY();
	x6=dist.getPointF1().getX();
	y6=dist.getPointF1().getY();
	dist.getPointE1().moveToPoint(Point(x0-x1+x5,y0-y1+y5,0));
	dist.getPointF1().moveToPoint(Point(x0-x1+x6,y0-y1+y6,0));
	rect.getPointE().moveToPoint(Point(x0-x1+x3,y0-y1+y3,0));
	rect.getPointF().moveToPoint(Point(x0-x2+x4,y0-y1+y4,0));
	rect.getPointD().moveToPoint(Point(x0-x1+x2,y0-y1+y2,0));
	rect.getPointC().moveToPoint(p);
};
//---------------------------------------------------------------------------
void Throat::moveTodXdY( double  x, double y)
{
	rect.getPointE().moveTodXdY(x,y);
	rect.getPointF().moveTodXdY(x,y);
	rect.getPointC().moveTodXdY(x,y);
	rect.getPointD().moveTodXdY(x,y);
	dist.getPointE1().moveTodXdY(x,y);
	dist.getPointF1().moveTodXdY(x,y);
}; 

//---------------------------------------------------------------------------
void Throat::consSF(Point P)
{
	rect.getPointE().consSP(P);
	rect.getPointF().consSP(P);
	rect.getPointC().consSP(P);
	rect.getPointD().consSP(P);
	dist.getPointE1().consSP(P);
	dist.getPointF1().consSP(P);
};
Rectangle Throat::getRect () 
{
	return rect;
};
Distance Throat::getDistance()
{
	return dist;
}
//---------------------------------------------------------------------------
const unsigned int Throat::getID()
{
  return id;
};
//---------------------------------------------------------------------------
unsigned int Throat::countObject()
{
  return count; 
};
